package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.StockMove;
import com.sumi.erp.service.IStockMoveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 调拨单Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/erp/move")
public class StockMoveController extends BaseController
{
    @Autowired
    private IStockMoveService stockMoveService;

    /**
     * 查询调拨单列表
     */
    @PreAuthorize("@ss.hasPermi('erp:move:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockMove stockMove)
    {
        startPage();
        List<StockMove> list = stockMoveService.selectStockMoveList(stockMove);
        return getDataTable(list);
    }

    /**
     * 导出调拨单列表
     */
    @PreAuthorize("@ss.hasPermi('erp:move:export')")
    @Log(title = "调拨单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockMove stockMove)
    {
        List<StockMove> list = stockMoveService.selectStockMoveList(stockMove);
        ExcelUtil<StockMove> util = new ExcelUtil<StockMove>(StockMove.class);
        util.exportExcel(response, list, "调拨单数据");
    }

    /**
     * 获取调拨单详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:move:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stockMoveService.selectStockMoveById(id));
    }

    /**
     * 新增调拨单
     */
    @PreAuthorize("@ss.hasPermi('erp:move:add')")
    @Log(title = "调拨单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockMove stockMove)
    {
        return toAjax(stockMoveService.insertStockMove(stockMove));
    }

    /**
     * 修改调拨单
     */
    @PreAuthorize("@ss.hasPermi('erp:move:edit')")
    @Log(title = "调拨单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockMove stockMove)
    {
        return toAjax(stockMoveService.updateStockMove(stockMove));
    }

    /**
     * 删除调拨单
     */
    @PreAuthorize("@ss.hasPermi('erp:move:remove')")
    @Log(title = "调拨单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockMoveService.deleteStockMoveByIds(ids));
    }
}
